package org.asdmp.restday.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.asdmp.restday.service.ParallelService;

/**
 * Servlet implementation class GetTaskController
 */
@WebServlet("/controller/redParallelGetTaskController")
public class RedParallelGetTaskController extends HttpServlet {
	private static final long serialVersionUID = 5L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RedParallelGetTaskController() {
        super();        
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();		 
		try {
			ParallelService service = new ParallelService();
			String processInstanceId = request.getParameter("processInstanceId");
			Set<String> names = service.getTasks(processInstanceId);
			String namesStr = "";
			for (String name:names){
				namesStr += name + ",";
			}
			if (names.size()>0) namesStr = namesStr.substring(0,namesStr.length()-1);
			request.setAttribute("responseText","到达节点名称========"+namesStr);
			request.setAttribute("fromnodes",namesStr);
			request.setAttribute("nodes",namesStr);
		} catch (Exception e){
			
		}
		request.getRequestDispatcher("../jsp/redparallelconsole.jsp").forward(request, response); 
	}

}
